package com.qingke.java.tools;

import java.io.InputStream;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class SessionManager {
	private static SessionManager sm;
	private SqlSessionFactory sessionFactory;
	
	private SessionManager() {
		String resource = "conf.xml";
		InputStream is = SessionManager.class.getClassLoader().getResourceAsStream(resource);
		sessionFactory = new SqlSessionFactoryBuilder().build(is);
	}
	
	public synchronized static SessionManager getInstance() {
		if(sm == null) {
			sm = new SessionManager();
		}
		return sm;
	}
	
	public SqlSession getSession() {
		return sessionFactory.openSession();
	}
	
}
